(function (define) {
    define([''], function () {
        var PageController = function ($rootScope, $scope, $location, $sce, Restangular) {
            $rootScope = angular.extend($rootScope, {
                name : 'Root scope'
            });

            $rootScope.$on('$viewContentLoaded', function(event) {
                skrollrRef.refresh();
                $(document).scrollTop(0);
            });

            $scope.awards = {};
            $scope.bookChapter = {};
            $scope.conference = {};
            $scope.editorship = {};
            $scope.grants = {};
            $scope.journal = {};
            $scope.lab = {};
            $scope.paperReviewers = {};
            $scope.personalData = {};
            $scope.publicDuty = {};
            $scope.selectedProject = {};
            $scope.students = {};
            $scope.teaching = {};

            Restangular.all('awards.json').getList().then(function(result){
                for (var i=0; i< result.length-1; i++) {
                    $scope.awards[i] = {};

                    $scope.awards[i].type = result[i].type;
                    $scope.awards[i].event = result[i].event;
                    $scope.awards[i].date = result[i].date;
                }
            });

            Restangular.all('bookChapter.json').getList().then(function(result){
                $scope.bookChapter = $sce.trustAsHtml(result.item);
            });

            Restangular.all('conference.json').getList().then(function(result){
                for (var i=0; i< result.length-1; i++) {
                    $scope.conference[i] = {};
                    $scope.conference[i].content = result[i].item;
                    $scope.conference[i].contentSafe = $sce.trustAsHtml(result[i].item);
                }
            });

            Restangular.all('editorship.json').getList().then(function(result){
                $scope.editorship = result;
            });

            Restangular.all('grants.json').getList().then(function(result){
                $scope.grants = result;
            });

            Restangular.all('journal.json').getList().then(function(result){
                $scope.journal = $sce.trustAsHtml(result.item);
            });

            Restangular.all('lab.json').getList().then(function(result){
                for (var i=0; i< result.length-1; i++) {
                    $scope.lab[i] = {};

                    $scope.lab[i].link = result[i].link;
                    $scope.lab[i].img = result[i].img;
                    $scope.lab[i].date = result[i].date;
                    $scope.lab[i].title = result[i].title;
                }
            });

            Restangular.all('paperReviewers.json').getList().then(function(result){
                for (var i=0; i< result.length-1; i++) {
                    $scope.paperReviewers[i] = {};

                    $scope.paperReviewers[i].title = result[i].title;
                }
            });

            Restangular.all('personalData.json').getList().then(function(result){
                $scope.personalData = result;
                $scope.personalData.mailingAddr = $sce.trustAsHtml(result.mailingAddr);
                $scope.personalData.description = $sce.trustAsHtml(result.description);
            });

            Restangular.all('publicDuty.json').getList().then(function(result){
                for (var i=0; i< result.length-1; i++) {
                    $scope.publicDuty[i] = {};
                    $scope.publicDuty[i].title = result[i].title;
                    $scope.publicDuty[i].link = result[i].link;
                }
            });

            Restangular.all('selectedProject.json').getList().then(function(result){
                for (var i=0; i< result.length-1; i++) {
                    $scope.selectedProject[i] = {};
                    $scope.selectedProject[i].titile = result[i].img;
                    $scope.selectedProject[i].link = result[i].link;
                }
            });

            Restangular.all('students.json').getList().then(function(result){
                for (var i=0; i< result.length-1; i++) {
                    $scope.students[i] = {};
                    $scope.students[i].img = result[i].img;
                    $scope.students[i].name = result[i].name;

                    for (var j=0; j< result[i].list.length; j++) {
                        $scope.students[i].list = new Array();
                        $scope.students[i].list[j] = {};
                        $scope.students[i].list[j].listContent = result[i].list[j];
                        $scope.students[i].list[j].listContentSafe = $sce.trustAsHtml(result[i].list[j]);
                    }
                }
            });

            Restangular.all('teaching.json').getList().then(function(result){
                for (var i=0; i< result.length-1; i++) {
                    $scope.teaching[i] = {};
                    $scope.teaching[i].date = result[i].date;
                    $scope.teaching[i].course = $sce.trustAsHtml(result[i].course);
                }
            });
        };

        return [ "$rootScope", "$scope", "$location", "$sce", "Restangular", PageController ];
    });
}(define));